#! /usr/bin/env node

let program = require('commander');

let {version} = require('./package.json');

const inquirer = require('inquirer');

const superagent = require('superagent')

const promptList = [
    // 具体交互内容
    {
    type: 'input',
    message: '请输入一个星座：:',
    name: 'star'
}
];

// program
//      .version(version,'-s -V  --version')
//      .parse(process.argv)

// program
//    .version('1.0.0')
//     .option('-a,--add','add something')
//     .option('-u,--update','update something')
//     .option('-r,--remove','remove somthing')
//     .parse(process.argv)
    
// console.log('You choose:');

// if(program.add) console.log(' add somthing')
// if(program.update) console.log(' update something')
// if(program.remove) console.log(' remove something')

let userlist  = [
    {
        username:'lixd',
        pwd:'123456'
    }
]

program
    .version('1.0.0')
    .action(() => {
        console.log("action 动作 登录");
        //收集用户信息，调登录接口
        inquirer.prompt(promptList).then(answers => {
            console.log(answers); // 返回的结果
            // //axios.post('')
            // let isSuccess = userlist.some((item) => {
            //     return item.username === answers.username && item.pwd === answers.pwd
            // })
            // if(isSuccess){
            //     console.log('登录成功')
            // }else{
            //     console.log('登录失败')
            // }

            superagent
  .get('http://web.juhe.cn:8080/constellation/getAll')
  .query({ key: '1e86cbe4ac7c8e1d23dcc5a133221f7b', type: 'today', consName:answers.star}) // query string
  
  .end((err, res) => {
    // Do something
    console.log(res)
  });
        })
    })
program.parse(process.argv);